package com.justgame.project.cloud.common.query;

import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.justgame.project.cloud.common.util.MyBatisUtils;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
public class QueryColumnAliasHandler implements Query.QueryHandler {
    @Override
    public void handle(Query query) {
        if (query.isMaster()){
            return;
        }
        String parentAlias = Optional.ofNullable(query.getParent()).map(parentQuery -> parentQuery.getAliasPrefix()+StringPool.DOT).orElse("");
        query.setAliasPrefix( parentAlias + query.getMappingFieldName());
    }

    @Override
    public int sort() {
        return 2;
    }
}
